import { defineConfig } from 'vite'
const { resolve } = require('path')
import vue from '@vitejs/plugin-vue'

import {
  createStyleImportPlugin,
  AndDesignVueResolve,
  VantResolve,
  ElementPlusResolve,
  NutuiResolve,
  AntdResolve
} from 'vite-plugin-style-import'
import { createHtmlPlugin } from 'vite-plugin-html'

export default defineConfig({
  base: './',
  // assetsInclude: resolve(__dirname, 'src/assets'),
  resolve: {
    // 别名
    alias: {
      '@': resolve(__dirname, 'src')
    }
  },
  // define: {
  //   'process.env': {
  //     ['BASE_API']: 'http://localhost:3000'
  //   }
  // },
  server: {
    proxy: {
      '^/api': {
        target: 'http://152.136.185.210:4000',
        rewrite: (path) => path.replace(/^\/api/, ''),
        changeOrigin: true
      }
    }
  },
  css: {
    preprocessorOptions: {
      less: {
        javascriptEnabled: true
      }
    }
  },
  plugins: [
    vue(),
    createStyleImportPlugin({
      resolves: [
        AndDesignVueResolve(),
        VantResolve(),
        ElementPlusResolve(),
        NutuiResolve(),
        AntdResolve()
      ],
      libs: [
        // If you don’t have the resolve you need, you can write it directly in the lib, or you can provide us with PR
        {
          libraryName: 'element-plus',
          esModule: true,
          resolveStyle: (name) => {
            return `element-plus/lib/theme-chalk/${name}.css`
          },
          resolveComponent: (name) => {
            return `element-plus/lib/${name}`
          }
        }
      ]
    }),
    createHtmlPlugin({
      template: 'public/index.html',
      entry: 'src/main.ts',
      minify: true,
      inject: {
        data: {
          title: 'index'
          // injectScript: `<script src="./inject.js"></script>`
        }
      }
    })
  ]
})
